package org.honeyweb.gsoc.pages;

import java.util.ArrayList;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry5.annotations.PageActivationContext;
import org.apache.tapestry5.annotations.PageLoaded;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.Service;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.honeyweb.gsoc.model.Organizations;
import org.honeyweb.gsoc.model.Users;
import org.honeyweb.gsoc.services.OrganizationsManager;
import org.honeyweb.gsoc.services.UsersManager;

@SuppressWarnings("unused")
public class Organization {

	private final Log logger = LogFactory.getLog(Organization.class);
	
	@Inject
	@Service("usersManager")
	private UsersManager usersManager;
	
	@Inject
	@Service("organizationsManager")
	private OrganizationsManager organizationsManager;
	
	@Property
	@PageActivationContext
	private Organizations organization;
	
	@Property
	@SessionState(create = true)
	private Users user;	
	
	@Property
	private Organizations organizationSelect;
	
	private Users administrator;

	public Users getAdministrator() {
		return usersManager.getAdmin(this.organization);
	}
	
	public ArrayList<Organizations> getListOrganizations() {
		return organizationsManager.getListOrganizations();	
	}
	
	/**
	 * Check if the current session user owns the organization displayed
	 * @return boolean
	 */
	public boolean getOrganizationOwner(){
		if (this.organization.getAdminId() == this.user.getIdUser()){
			return true;
		}
		else{
			return false;
		}
	}
	
}
